#include "MediaSrcBuilder.h"
#include "BusinessDNA.h"
#include "MP4MediaSource.h"
#include "TimeBufMediaSource.h"
#include "RWMediaSource.h"
#include "FlvMediaSource.h"
#include "SDPMediaSource.h"
#include "PullMediaSource.h"
#include "RTMediaSource.h"
#include "Globle.h"

CMediaSource* CMediaSrcBuilder::CreateMediaSrc(CBusinessDNA &inBusinessDNA)
{
	CMediaSource *pSource = NULL;
	EFromWhere eFrom = inBusinessDNA.GetFromWhere();
	switch(eFrom) {
	case W_NET:
	{
		EFileFormat eFormat = inBusinessDNA.GetFileFormat();
		switch( eFormat )
		{
		case N_TCPPUSH:
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CPullMediaSource");
			pSource = new CPullMediaSource;
			break;
		default:
			if(SConfigPara::m_isNeedLiveFastForward &&
				inBusinessDNA.GetServiceType() == P_RTSP &&
				inBusinessDNA.GetClientType() == C_RTPSESSION &&
				inBusinessDNA.GetFileFormat() == F_SDP)
			{
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CRTMediaSource");
				pSource = new CRTMediaSource;
			}
 			else
			{
				pSource = new CTimeBufMediaSource;
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CTimeBufMediaSource");
			}
			break;
		}
		break;
	}
	case W_LOCAL:
		{
			EFileFormat eFormat = inBusinessDNA.GetFileFormat();
			switch(eFormat) {
			case F_MP4:
			case F_3GP: 
			case F_3G2:
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CMP4MediaSource");
					pSource = new CMP4MediaSource;
				break;
			case F_FLV:
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CFlvMediaSource");
				pSource = new CFlvMediaSource;
				break;
			case F_ASF:
			case F_WMV:
			case F_RM:
				pSource = new CRWMediaSource;
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CRWMediaSource");
				break;
			case F_SDP:
				if(SConfigPara::m_isNeedLiveFastForward &&
					inBusinessDNA.GetServiceType() == P_RTSP &&
					inBusinessDNA.GetClientType() == C_RTPSESSION)
				{
					pSource = new CRTMediaSource;
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CRTMediaSource");
				}
				else
				{
					pSource = new CSDPMediaSource;
			OutputDebugStringA("CMediaAdapter::Setup CMediaSrcBuilder::CreateMediaSrc CRTMediaSource");
				}
				break;
			default:
				break;
			}
		}
		break;
	default:
		break;
	}

	return pSource;
}
